package com.sunshine.boot;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * Demo class
 *
 * @author WeiHong
 * @date 2018/11/6
 */
@SpringBootApplication
public class TestProfiles {

    public static void main(String[] args) {
        ConfigurableApplicationContext context1 = new SpringApplicationBuilder(TestProfiles.class)
                .properties(
                        "spring.config.location=classpath:/config/test-profiles.yml")
                .properties("spring.profiles.active=oracle")
                .run(args);
        String oracle = context1.getEnvironment().getProperty("jdbc.driver");
        System.out.println("oracle = " + oracle);
        // 启动第二个Spring容器，指定端口为8081
        ConfigurableApplicationContext context2 = new SpringApplicationBuilder(TestProfiles.class)
                .properties(
                        "spring.config.location=classpath:/config/test-profiles.yml")
                .properties("spring.profiles.active=mysql")
                .properties("server.port=8081")
                .run(args);
        String mysql = context2.getEnvironment().getProperty("jdbc.driver");
        System.out.println("mysql = " + mysql);
    }
}
